package cn.backpackerxl.easyJDBC.main;

import cn.backpackerxl.easyJDBC.util.StringUtil;

/**
 * @Author: backpackerxl
 * CreateTime: 2022/5/23
 * FileName: BasicServiceImpl
 **/
public class BasicServiceImpl {
    private BasicServiceImpl() {
    }

    public static String save(Class<?> clazz, String name) {
        String type = BasicEntity.type(clazz.getName());
        String small = StringUtil.headSmall(type);
        return "\t@Override\n" + "\tpublic int add(" + type + " " + small + ") {\n" + "\t\treturn " + name + ".save(" + small + ");" + "\n\t}\n\n";
    }

    public static String update(Class<?> clazz, String name) {
        String type = BasicEntity.type(clazz.getName());
        String small = StringUtil.headSmall(type);
        return "\t@Override\n" + "\tpublic int edit(" + type + " " + small + ") {\n" + "\t\treturn " + name + ".update(" + small + ");" + "\n\t}\n\n";
    }

    public static String remove(String name) {
        return "\t@Override\n" + "\tpublic int delete(Long id) {\n" + "\t\treturn " + name + ".remove(id);" + "\n\t}\n\n";
    }

    public static String findById(Class<?> clazz, String name) {
        return "\t@Override\n" + "\tpublic " + BasicEntity.type(clazz.getName()) + " selectById(Long id) {\n" + "\t\treturn " + name + ".findById(id);" + "\n\t}\n\n";
    }

    public static String findAll(Class<?> clazz, String name) {
        return "\t@Override\n" + "\tpublic List<" + BasicEntity.type(clazz.getName()) + "> selectAll() {\n" + "\t\treturn " + name + ".findAll();" + "\n\t}\n\n";
    }


    public static String autoImport(Class<?> clazz, String outName, String daoPack, String daoName, String fileName) {
        return "import " + clazz.getName() + ";\n" + "import " + outName + "." + fileName + ";\n" + "import " + daoPack + "." + daoName + ";\n" + "import cn.backpackerxl.easyJDBC.main.EasyJDBCRepository;\n\n" + "import java.util.List;\n";
    }

    public static String autoImport(Class<?> clazz) {
        return "import " + clazz.getName() + ";\n" + "import cn.backpackerxl.easyJDBC.main.EasyJDBCRef;\n\n";
    }
}
